package plsqlfs;

import java.sql.SQLData;
import java.sql.SQLException;
import java.sql.SQLInput;
import java.sql.SQLOutput;

public class FileSystemException extends RuntimeException implements SQLData {

	private static final long serialVersionUID = 694868827135055394L;

	/**
	 * The error code returned if a file could not be found.
	 */
	public static final int UNKNOWN = -20109;
	public static final int FILE_NOT_FOUND = -20110;
	public static final int COULD_NOT_DELETE = -20111;
	public static final int NON_FILE = -20112;
	public static final int NON_DIRECTORY = -20113;
	public static final int INSUFFICIENT_PRIVILEGES = -20114;
	public static final int DIRECTORY_NOT_FOUND = -20115;
	public static final int ENVIRONMENT_VARIABLE_NOT_FOUND = -20116;

	private final int code;
	private String typeName;

	public FileSystemException(int code) {
		super();
		this.code = code;
	}

	public FileSystemException(int code, String message, Throwable cause) {
		super(message, cause);
		this.code = code;
	}

	public FileSystemException(int code, String message) {
		super(message);
		this.code = code;
	}

	public FileSystemException(int code, Throwable cause) {
		super(cause);
		this.code = code;
	}

	public int getCode() {
		return code;
	}

	public String getSQLTypeName() throws SQLException {
		return typeName;
	}

	public void setSQLTypeName(String typeName) {
		this.typeName = typeName;
	}

	public void readSQL(SQLInput stream, String typeName) throws SQLException {
		this.typeName = typeName;
	}

	public void writeSQL(SQLOutput stream) throws SQLException {
		stream.writeInt(getCode());
		stream.writeString(getMessage());
	}

}